package com.mymaxis.ws;


import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import com.mymaxis.service.EmailSubscriptionInfo;
import com.mymaxis.service.StmtDownloadService;

import org.apache.axiom.om.OMAbstractFactory;
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMFactory;
import org.apache.axiom.om.OMNamespace;
import org.apache.axiom.om.OMText;

import com.mymaxis.dao.AccDao;
import com.mymaxis.dao.AccInfoDao;
import com.mymaxis.dao.AccInfoListDao;
import com.mymaxis.dao.HeaderInfoDao;
import com.mymaxis.dao.StatementDetailsDao;
import com.mymaxis.dao.StatementTypeDao;
import com.mymaxis.domain.StmtSummaryInfo;
import com.mymaxis.domain.UpdateSubscriptionInfoResponse;
import com.mymaxis.ebppx.EbppxAcctDetailsDataBean;
import com.mymaxis.ebppx.EbppxConstants;
import com.mymaxis.ebppx.WsConstants;
import com.mymaxis.service.AcctDetails;
import com.mymaxis.service.GetPdfBill_WS;
import com.mymaxis.utils.AccountInfo;
import com.mymaxis.utils.EmailNotification;
import com.mymaxis.utils.EncryptionHelper;
import com.mymaxis.utils.LogWriter;



public class receiveWs {
	
	
	public static OMElement GetPDFStmtViaStmtID(HeaderInfoDao Header,StatementTypeDao Parameter)throws Exception{

		OMFactory factory = OMAbstractFactory.getOMFactory();		
		OMNamespace ns1 = factory.createOMNamespace("", "");	
		OMElement root = factory.createOMElement("Root", ns1);
		boolean status=false;
		String badResponseID = null;
		String badResponseDesc = null;
		String strAppName = Header.getAppName();
		String strAppID = Header.getAppID();
		String strReqID = Header.getReqID();
		String strStmtId = Parameter.getStmtID();
		String strStmtType = Parameter.getStmtType();
		OMElement el100 = factory.createOMElement("ResultBody", ns1);
		OMElement el101 = factory.createOMElement("Header", ns1);
		OMElement el101reqID = factory.createOMElement("reqID", ns1);	
		OMElement el201 = factory.createOMElement("Binary", ns1);
		OMElement el301 = factory.createOMElement("BadResponse", ns1);
		OMElement el3011 = factory.createOMElement("responseCode", ns1);
		OMElement el3012 = factory.createOMElement("responseDesc", ns1);

	
		el101reqID.setText(strReqID);
		el101.addChild(el101reqID);
        System.out.println("strStmtType :"+strStmtType);
        
        //LogWriter sl = new LogWriter();
		/**
		 * LOG MESSAGE REQUEST
		 */
		String logMsg = "AppID: " + Header.getAppID() + 
				"\nAppName: " + Header.getAppName() +
				"\nReqID: " + Header.getReqID() +
				"\nStmtID: " + Parameter.getStmtID() +
				"\nStmtType " + Parameter.getStmtType();
		LogWriter writer = new LogWriter();
		writer.doLogging(strReqID, "", "GetPDFStmtViaStmtID", "", logMsg);
        
        if (!strAppID.equalsIgnoreCase("") && strAppID != null && !"?".equalsIgnoreCase(strAppID)) {
        	
        		if (!strAppName.equalsIgnoreCase("") && strAppName != null && !"?".equalsIgnoreCase(strAppName)) {
				
					if (!strReqID.equalsIgnoreCase("") && strReqID != null && !"?".equalsIgnoreCase(strReqID)) {
						
						if (strStmtId.matches("^[0-9]{1,20}$")&& !strStmtId.equalsIgnoreCase("") && strStmtId != null&& !"?".equalsIgnoreCase(strStmtId)) {
							
							if(strStmtType.equalsIgnoreCase(WsConstants.PDF_FILE)){
								
								status = true;
								
							}else{
								badResponseID = WsConstants.BAD_RESPONSE_CODE_0009;
								badResponseDesc = WsConstants.BAD_RESPONSE_DESC_0009;
							}
						}else{
							
							badResponseID = WsConstants.BAD_RESPONSE_CODE_0008;
							badResponseDesc = WsConstants.BAD_RESPONSE_DESC_0008;
						}
						
					} else {
						
						badResponseID = WsConstants.BAD_RESPONSE_CODE_0005;
						badResponseDesc = WsConstants.BAD_RESPONSE_DESC_0005;
						
					}
					
				} else {
					
					badResponseID = WsConstants.BAD_RESPONSE_CODE_0003;
					badResponseDesc = WsConstants.BAD_RESPONSE_DESC_0003;
					
			    }
				
			} else {
				
			
				badResponseID = WsConstants.BAD_RESPONSE_CODE_0004;
				badResponseDesc = WsConstants.BAD_RESPONSE_DESC_0004;
				
			}
		
		if(status){
		
			StmtDownloadService stmtObject = new StmtDownloadService();
			javax.activation.DataHandler dataHandler   =stmtObject.getStmtViaStmtId(strStmtId, strStmtType);
		
			if(dataHandler !=null){
				
				OMText textData = factory.createOMText(dataHandler, true);
				el201.addChild(textData);
				el100.addChild(el201);
				
			}else{
				
			
				badResponseID = WsConstants.BAD_RESPONSE_CODE_0002;
				badResponseDesc = WsConstants.BAD_RESPONSE_DESC_0002;
				el3011.setText(badResponseID);
				el3012.setText(badResponseDesc);
				el301.addChild(el3011);
				el301.addChild(el3012);
				el100.addChild(el301);
			}
	
		
		}else{
			
			el3011.setText(badResponseID);
			el3012.setText(badResponseDesc);
			el301.addChild(el3011);
			el301.addChild(el3012);
			el100.addChild(el301);
		}
		
		root.addChild(el101);
		root.addChild(el100);
		
		writer.doLogging(strReqID, "", "GetPDFStmtViaStmtIDResponse", "", root.toString());
		return root;
		
		
		
	}
	
	public static OMElement GetStmtSummaryViaStmtID(HeaderInfoDao Header,StatementTypeDao Parameter)throws Exception{
		
		OMFactory factory = OMAbstractFactory.getOMFactory();		
		OMNamespace ns1 = factory.createOMNamespace("", "");	
		OMElement root = factory.createOMElement("Root", ns1);
		
		boolean status=false;
		String badResponseID = null;
		String badResponseDesc = null;
		String strAppName = Header.getAppName();
		String strAppID = Header.getAppID();
		String strReqID = Header.getReqID();
		String strStmtId = Parameter.getStmtID();
		String strStmtType = Parameter.getStmtType();
		System.out.println("strAppName :"+strAppName);
		System.out.println("strAppID :"+strAppID);
		System.out.println("strAppID :"+strAppID);
		OMElement el100 = factory.createOMElement("ResultBody", ns1);
		OMElement el101 = factory.createOMElement("Header", ns1);
		OMElement el101reqID = factory.createOMElement("reqID", ns1);	
		OMElement el301 = factory.createOMElement("BadResponse", ns1);
		OMElement el3011 = factory.createOMElement("responseCode", ns1);
		OMElement el3012 = factory.createOMElement("responseDesc", ns1);
		
		
		LogWriter writer = new LogWriter();
		String logMsg = "AppID: " + Header.getAppID() + 
				"\nAppName: " + Header.getAppName() +
				"\nReqID: " + Header.getReqID() +
				"\nStmtID: " + Parameter.getStmtID() +
				"\nStmtType " + Parameter.getStmtType();
		writer.doLogging(strReqID, "", "GetStmtSummaryViaStmtID", "", logMsg);
		
		el101reqID.setText(strReqID);
		el101.addChild(el101reqID);
		  
        if (!strAppID.equalsIgnoreCase("") && strAppID != null && !"?".equalsIgnoreCase(strAppID)) {
        	
        		if (!strAppName.equalsIgnoreCase("") && strAppName != null && !"?".equalsIgnoreCase(strAppName)) {
				
					if (!strReqID.equalsIgnoreCase("") && strReqID != null && !"?".equalsIgnoreCase(strReqID)) {
						
						if (strStmtId.matches("^[0-9]{1,20}$")&& !strStmtId.equalsIgnoreCase("") && strStmtId != null&& !"?".equalsIgnoreCase(strStmtId)) {
							
							if(strStmtType.equalsIgnoreCase(WsConstants.SUM_FILE)){
								
								status = true;
								
							}else{
								badResponseID = WsConstants.BAD_RESPONSE_CODE_0009;
								badResponseDesc = WsConstants.BAD_RESPONSE_DESC_0009;
							}
						}else{
							
							badResponseID = WsConstants.BAD_RESPONSE_CODE_0008;
							badResponseDesc = WsConstants.BAD_RESPONSE_DESC_0008;
						}
						
					} else {
						
						badResponseID = WsConstants.BAD_RESPONSE_CODE_0005;
						badResponseDesc = WsConstants.BAD_RESPONSE_DESC_0005;
						
					}
					
				} else {
					
					badResponseID = WsConstants.BAD_RESPONSE_CODE_0003;
					badResponseDesc = WsConstants.BAD_RESPONSE_DESC_0003;
					
			    }
				
		  } else {
				
			
				badResponseID = WsConstants.BAD_RESPONSE_CODE_0004;
				badResponseDesc = WsConstants.BAD_RESPONSE_DESC_0004;
				
			}
        
       
        if(status){
        	
        	StmtDownloadService stmtSummary = new StmtDownloadService();
    		StmtSummaryInfo stmtInfo = stmtSummary.getStmtSummaryViaStmtID(strStmtId, "SUM");
    		System.out.println("STMTINFO :"+stmtInfo);
    		List lineDetailsHdr = new ArrayList();
    		int sizeStmtInfo = stmtInfo.getLineDetail().size();
    		System.out.println("SIZE : "+sizeStmtInfo);
    		System.out.println("LINE DETAILS :");
    		if(sizeStmtInfo != 0){
    		    System.out.println("Test function");
    			OMElement el3001 = factory.createOMElement("StatementDate", ns1);
    			OMElement el3002 = factory.createOMElement("OverDue", ns1);
    			OMElement el3003 = factory.createOMElement("TotalAmountDue", ns1);
    			OMElement el3004 = factory.createOMElement("ServiceTax", ns1);
    			OMElement el3006 = factory.createOMElement("DiscountAndRebates",ns1);
    			OMElement el3005 = factory.createOMElement("TotalAmount", ns1);
    			//totalAmount
    			
    			el3001.setText(stmtInfo.getStmtDate());
    			el3002.setText(stmtInfo.getOverDue());
    			el3003.setText(stmtInfo.getTotalAmtDue());
    			el3004.setText(stmtInfo.getServiceTax());
    			el3006.setText(stmtInfo.getDiscountAndRebates());
    			el3005.setText(stmtInfo.getTotalAmt());
    			el100.addChild(el3001);
    			el100.addChild(el3002);
    			el100.addChild(el3003);
    			el100.addChild(el3004);
    			el100.addChild(el3006);
    			el100.addChild(el3005);
    			lineDetailsHdr = stmtInfo.getLineDetail();
    			System.out.println("lineDetailsHdr.size() :"+lineDetailsHdr.size());
    			
    			for(int i=0;i<lineDetailsHdr.size();i++){
    				
    				OMElement el400 = factory.createOMElement("LineDetailsHdr", ns1);
        			OMElement el4001 = factory.createOMElement("LineDetailsDtl", ns1);
        			OMElement el4002 = factory.createOMElement("lineNumber", ns1);
        			OMElement el4003 = factory.createOMElement("lineTotal", ns1);
    				String[] details = lineDetailsHdr.get(i).toString().split(",");
		 			
    				el4002.setText(details[0]);
    				el4003.setText(details[1]);
    				el4001.addChild(el4002);
    				el4001.addChild(el4003);
    				el400.addChild(el4001);
    				el100.addChild(el400);
    				
    			}
    			
    	
    		}else{
    			
    			badResponseID = WsConstants.BAD_RESPONSE_CODE_0002;
				badResponseDesc = WsConstants.BAD_RESPONSE_DESC_0002;
				el3011.setText(badResponseID);
				el3012.setText(badResponseDesc);
				el301.addChild(el3011);
				el301.addChild(el3012);
				el100.addChild(el301);
    			
    		}
        }else{
        	
        	 	el3011.setText(badResponseID);
        	 	el3012.setText(badResponseDesc);
        	 	el301.addChild(el3011);
        	 	el301.addChild(el3012);
        	 	el100.addChild(el301);
        	
        }
		
		
		root.addChild(el101);
		root.addChild(el100);
		

		writer.doLogging(strReqID, "", "GetStmtSummaryViaStmtIDResponse", "", root.toString());
		
		
		return root;
	}
	
	public static OMElement GetSubscriptionInfo(HeaderInfoDao Header,AccDao Parameter)throws Exception{
		

		OMFactory factory = OMAbstractFactory.getOMFactory();		
		OMNamespace ns1 = factory.createOMNamespace("", "");	
		OMElement root = factory.createOMElement("Root", ns1);
		
		boolean status=false;
	    DateFormat date = new SimpleDateFormat("ddMMyyyy");
	    DateFormat time = new SimpleDateFormat("HHmmss");
	    String modifyDate = "";
	    String modifyTime = "";
		String badResponseID = null;
		String badResponseDesc = null;
		String strAppName = Header.getAppName();
		String strAppID = Header.getAppID();
		String strReqID = Header.getReqID();
		String accountSub ="";
		String emailSub ="";
		String smsSub ="";
		String emailSubStatus = "";

		
		LogWriter writer = new LogWriter();
		String acctNo = Parameter.getExtAccNo();
		
		String logMsg = "AppID: " + Header.getAppID() + 
				"\nAppName: " + Header.getAppName() +
				"\nReqID: " + Header.getReqID() +
				"\nAcctNo: " + Parameter.getExtAccNo();
				
		writer.doLogging(strReqID, "", "GetSubscriptionInfo", "", logMsg);
		
		
		   if (!strAppName.equalsIgnoreCase("") && strAppName != null && !"?".equalsIgnoreCase(strAppName)) {
				
				if (!strAppID.equalsIgnoreCase("") && strAppID != null && !"?".equalsIgnoreCase(strAppID)) {
					
					if (!strReqID.equalsIgnoreCase("") && strReqID != null && !"?".equalsIgnoreCase(strReqID)) {
						
						if(!acctNo.equalsIgnoreCase("") && acctNo != null && !"?".equalsIgnoreCase(acctNo)){
							
							status=true;
						}else{
							
							
							badResponseID = WsConstants.BAD_RESPONSE_CODE_0011;
							badResponseDesc = WsConstants.BAD_RESPONSE_DESC_00011;
						}
						
					} else {
						
						badResponseID = WsConstants.BAD_RESPONSE_CODE_0005;
						badResponseDesc = WsConstants.BAD_RESPONSE_DESC_0005;
						
					}
					
				} else {
					
					badResponseID = WsConstants.BAD_RESPONSE_CODE_0004;
					badResponseDesc = WsConstants.BAD_RESPONSE_DESC_0004;
					
			    }
				
			} else {
				
				badResponseID = WsConstants.BAD_RESPONSE_CODE_0003;
				badResponseDesc = WsConstants.BAD_RESPONSE_DESC_0003;
				
			}

		
		
		OMElement el100 = factory.createOMElement("ResultBody", ns1);
		OMElement el101 = factory.createOMElement("Header", ns1);
		OMElement el101reqID = factory.createOMElement("reqID", ns1);	
		OMElement el201 = factory.createOMElement("GetSubscriptionInfo", ns1); 
		OMElement el2011 = factory.createOMElement("extAccNo", ns1); 
		OMElement el2012 = factory.createOMElement("hcSuppressSubscription", ns1); 
		OMElement el2013 = factory.createOMElement("emailBillSubscription", ns1); 
		OMElement el2014 = factory.createOMElement("emailAddress", ns1); 
		OMElement el2015 = factory.createOMElement("smsAlertFlag", ns1); 
		OMElement el2016 = factory.createOMElement("smsNo", ns1); 
		OMElement el2017 = factory.createOMElement("emailSubscriptionStatus", ns1);
		OMElement el2018 = factory.createOMElement("updatedDate", ns1);
		OMElement el2019 = factory.createOMElement("updatedTime", ns1);
		OMElement el20110 = factory.createOMElement("updatedBy", ns1);
		OMElement el20111 = factory.createOMElement("updatedChannel", ns1);
	
		OMElement el301 = factory.createOMElement("BadResponse",ns1);
		OMElement el3011 = factory.createOMElement("responseCode",ns1);
		OMElement el3012 = factory.createOMElement("responseDesc",ns1);
		
		el101reqID.setText(strReqID);
		el101.addChild(el101reqID);
		
		
		if(status){

		   EmailSubscriptionInfo acctDetailsObj =new EmailSubscriptionInfo();
		   EbppxAcctDetailsDataBean acctDetails = acctDetailsObj.getSubscriptionInfo(acctNo,strAppID,strAppName);
		   EbppxAcctDetailsDataBean acctDetails2 = AcctDetails.getAcctDetails(acctNo);
		   System.out.println("USER:"+acctDetails.getUpdatedByUser());
		   if(acctDetails != null){
			 
			   Date lastModifyDate = acctDetails.getLastModifyDate();
			   System.out.println("lastModifyDate :"+lastModifyDate);
			   if(lastModifyDate !=null){
				  
				   modifyDate = date.format(lastModifyDate);
				   modifyTime = time.format(lastModifyDate);
			   }
			 
               if(acctDetails.getExceptionMsg().equalsIgnoreCase(EbppxConstants.ACCT_NOT_FOUND)){
        	     
            	  el3011.setText(WsConstants.BAD_RESPONSE_CODE_0001);
        	      el3012.setText(WsConstants.BAD_RESPONSE_DESC_0001);
        	      el301.addChild(el3011);
        	      el301.addChild(el3012);
        	      
        	      el100.addChild(el301);
        	      
	           }else{
	        	  
	        	  //accountSub = acctDetails2.getAcctSubscription();
	        	  emailSub = acctDetails2.getEmailSubscription();
	        	  smsSub = acctDetails.getSMSSubscription();
	        	  emailSubStatus = acctDetails.getEmailStatus();
	        	  if(emailSub.equals("1")){
	        		  emailSub = "Y";
	        		  accountSub = "Y";
	        	  }else{
	        		  emailSub = "N";
	        		  accountSub = "N";
	        	  }
	        	
	        	  if(!emailSubStatus.equals("P")){
	        		  
	        			  if(emailSub.equalsIgnoreCase("Y")){
		        			  emailSubStatus = "A";
		        		  }else{
		        			  
		        			  emailSubStatus = "N";
		        		  }
	        		
	        		  
	        	  }else {
	        		  emailSubStatus = "P";
	        		  
	        		  
	        	  }
	        
	        	  
	        	 /* if(emailSub.equalsIgnoreCase("0") || emailSub.equalsIgnoreCase("")){
	        		  
	        		  emailSub = "N";
	        		  emailSubStatus = "N";
	        		  accountSub = "N";
	        		  
	        	  }else if(emailSub.equalsIgnoreCase("1")){
	        		  
	        		  emailSub = "Y";
	        		  emailSubStatus = "A";
	        		  accountSub ="Y";
	        		  
	        	  }else if(emailSub.equalsIgnoreCase("P")){
	        		  
	        		  emailSub = "Y";
	        		  emailSubStatus = "P";
	        		  accountSub ="Y";
	        	  }else if(emailSub.equalsIgnoreCase("X")){
	        		  
	        		  emailSub = "N";
	        		  accountSub ="N";
	        		  emailSubStatus = "P";
	        		  
	        	  }
	        	  */
	        	  if(smsSub.equalsIgnoreCase("0") || smsSub.equalsIgnoreCase("")){
	        		  
	        		  smsSub = "N";
	        	  }else if(smsSub.equalsIgnoreCase("1")){
	        		  
	        		  smsSub = "Y";
	        	  }
	        	  
	        	  
	    	      el2011.setText(acctDetails.getAcctId());
	   		      el2012.setText(accountSub);
	   		      el2013.setText(emailSub);
	   		      el2014.setText(acctDetails.getEmailAdd());
	   		      el2015.setText(smsSub);
	   		      el2016.setText(acctDetails.getSMSNo());
	   		      el2017.setText(emailSubStatus);
	   		      el2018.setText(modifyDate);
	   		      el2019.setText(modifyTime);
	   		      el20110.setText(acctDetails.getUpdatedByUser());
	   		      el20111.setText(acctDetails.getUpdatedByChannel());
	   		
	   		      el201.addChild(el2011);
	   		      el201.addChild(el2012);
	   		      el201.addChild(el2013);
	   		      el201.addChild(el2014);
	   		      el201.addChild(el2015);
	   		      el201.addChild(el2016);
	   		      el201.addChild(el2016);
	   		      el201.addChild(el2017);
	   		      el201.addChild(el2018);
	   		      el201.addChild(el2019);
	   		      el201.addChild(el20110);
	   		      el201.addChild(el20111);
	   		      el100.addChild(el201);
	       }
			
		   }
		}else{
		
		  el3011.setText(badResponseID);
  	      el3012.setText(badResponseDesc);
  	      el301.addChild(el3011);
  	      el301.addChild(el3012);
  	      el100.addChild(el301);
  	    
		}

		root.addChild(el101);
		root.addChild(el100);
		
	
				
		writer.doLogging(strReqID, "", "GetSubscriptionInfoResponse", "", root.toString());
		
		return root;
	}
	
	public static OMElement UpdateSubscriptionInfo(HeaderInfoDao Header,AccInfoListDao Parameter)throws Exception{
		final String passphrase = "X2q3j5k6E7r8l93tm2n7H5qp";

		OMFactory factory = OMAbstractFactory.getOMFactory();	
		LogWriter writer = new LogWriter();		
		OMNamespace ns1 = factory.createOMNamespace("", "");	
		OMElement root = factory.createOMElement("Root", ns1);
		OMElement el100 = factory.createOMElement("ResultBody", ns1);
		OMElement el101 = factory.createOMElement("Header", ns1);
		OMElement el101reqID = factory.createOMElement("reqID", ns1);	
		OMElement el301 = factory.createOMElement("BadResponse",ns1);
		OMElement el3011 = factory.createOMElement("responseCode",ns1);
		OMElement el3012 = factory.createOMElement("responseDesc",ns1);
		boolean status	=	false;
		String strAppName = Header.getAppName();
		String strAppID = Header.getAppID();
		String strReqID = Header.getReqID();
		AccInfoDao[] list =	Parameter.getAccountInfo();
		String updateByUser = Parameter.getUpdatedBy();
		String updateByChannel = Parameter.getUpdatedChannel();
		
		String badResponseID = null;
		String badResponseDesc = null;
		

		

		if (!strAppID.equalsIgnoreCase("") && strAppID != null && !"?".equalsIgnoreCase(strAppID)) {
		   
			if (!strAppName.equalsIgnoreCase("") && strAppName != null && !"?".equalsIgnoreCase(strAppName)) {
				
				
					
					if (!strReqID.equalsIgnoreCase("") && strReqID != null && !"?".equalsIgnoreCase(strReqID)) {
						
							
							status=true;
						
						
					} else {
						
						badResponseID = WsConstants.BAD_RESPONSE_CODE_0005;
						badResponseDesc = WsConstants.BAD_RESPONSE_DESC_0005;
						
					}
					
				} else {
					
					badResponseID = WsConstants.BAD_RESPONSE_CODE_0003;
					badResponseDesc = WsConstants.BAD_RESPONSE_DESC_0003;
				
					
			    }
				
			} else {
				
				badResponseID = WsConstants.BAD_RESPONSE_CODE_0004;
				badResponseDesc = WsConstants.BAD_RESPONSE_DESC_0004;
				
			}

		
		el101reqID.setText(strReqID);
		el101.addChild(el101reqID);
		
		if(status){
		
			for(int i=0;i<list.length;i++){
				
				AccInfoDao acctInfoDao = new AccInfoDao();
				acctInfoDao = list[i];
				if(acctInfoDao !=null){
				
				OMElement el201 = factory.createOMElement("AccountInfo", ns1);				
				OMElement el2011 = factory.createOMElement("extAccNo", ns1); 
				OMElement el2012 = factory.createOMElement("status", ns1); 
				OMElement el2013 = factory.createOMElement("failMsg", ns1); 
				String extAccNo = acctInfoDao.getExtAccNo();
				String hcSuprssSubscript = acctInfoDao.getHcSuppressSubscription();
				String emailBillSubscript = acctInfoDao.getEmailBillSubscription();
				String emailAddrs = acctInfoDao.getEmailAddress();
				String smsAlertFlag = acctInfoDao.getSmsAlertFlag();
				String smsNo = acctInfoDao.getSmsNo();
				System.out.println("emailBillSubscript :"+emailBillSubscript);
				System.out.println("extAccNo :"+extAccNo);
				System.out.println("hcSuprssSubscript :"+hcSuprssSubscript);
				System.out.println("smsAlertFlag :"+smsAlertFlag);
				System.out.println("smsNo :"+smsNo);
				
				
				String logMsg = "AppID: " + Header.getAppID() + 
						"\nAppName: " + Header.getAppName() +
						"\nReqID: " + Header.getReqID() +
						"\nAcctNo: " + extAccNo +
						"\nhcSuprssSubscript : " + hcSuprssSubscript+
						"\nemailBillSubscript : "+emailBillSubscript+
						"\nemailAddrs : "+emailAddrs+
						"\nsmsAlertFlag : "+smsAlertFlag+
						"\nsmsNo : "+smsNo+
						"\nupdateByChannel : "+updateByChannel+
						"\nupdateByUser : "+updateByUser;
						
				
				writer.doLogging(strReqID, "", "UpdateSubscriptionInfo", "", logMsg);
				
				
				EmailSubscriptionInfo updateObj = new EmailSubscriptionInfo();
				
				UpdateSubscriptionInfoResponse reponseObj = updateObj.UpdateSubscriptionInfo(emailAddrs,emailBillSubscript,extAccNo,hcSuprssSubscript,smsAlertFlag,smsNo,updateByUser,updateByChannel);
				
				el2011.setText(reponseObj.getExtAcctNo());
				el2012.setText(reponseObj.getUpdateStatus());
				el2013.setText(reponseObj.getFailMsg());
				el201.addChild(el2011);
				el201.addChild(el2012);
				el201.addChild(el2013);
				el100.addChild(el201);
			}
			
			}
		}else{
		
		  el3011.setText(badResponseID);
	      el3012.setText(badResponseDesc);
	      el301.addChild(el3011);
	      el301.addChild(el3012);
	      el100.addChild(el301);
	  
		}
		
	
	

		root.addChild(el101);
		root.addChild(el100);
		
	
				
				
		writer.doLogging(strReqID, "", "UpdateSubscriptionInfoResponse", "", root.toString());
		
		return root;
	}
	
	
public static OMElement GetStatementList(HeaderInfoDao Header,AccDao Parameter)throws Exception{

		OMFactory factory = OMAbstractFactory.getOMFactory();		
		OMNamespace ns1 = factory.createOMNamespace("", "");	
		OMElement root = factory.createOMElement("Root", ns1); 
		
		OMElement el100 = factory.createOMElement("ResultBody", ns1);
		OMElement el101 = factory.createOMElement("Header", ns1);
		OMElement el101reqID = factory.createOMElement("reqID", ns1);	
		OMElement el102 = factory.createOMElement("GetStatementList", ns1);
		
		OMElement el301 = factory.createOMElement("BadResponse", ns1);
		OMElement el3011 = factory.createOMElement("responseCode", ns1);
		OMElement el3012 = factory.createOMElement("responseDesc", ns1);
		LogWriter writer = new LogWriter();		
		StmtDownloadService object = new StmtDownloadService();
		boolean status=false;
		List listOfStatement = new ArrayList();
		String badResponseID = null;
		String badResponseDesc = null;
		
		String strAppName = Header.getAppName();
		String strAppID = Header.getAppID();
		String strReqID = Header.getReqID();
		
		el101reqID.setText(strReqID);
		el101.addChild(el101reqID);
		
		String acctNo = Parameter.getExtAccNo();
		
		
		String logMsg = "AppID: " + Header.getAppID() + 
				"\nAppName: " + Header.getAppName() +
				"\nReqID: " + Header.getReqID() +
				"\nAcctNo: " + acctNo ;
				
			
				
				
		writer.doLogging(strReqID, "", "GetStatementList", "", logMsg);
		
		if(strAppName !=null && !strAppName.equalsIgnoreCase("?") && !strAppName.equalsIgnoreCase("")){
			
			if(strAppID !=null && !strAppID.equalsIgnoreCase("?") && !strAppID.equalsIgnoreCase("")){
				
					if(strReqID !=null && !strReqID.equalsIgnoreCase("?") && !strReqID.equalsIgnoreCase("")){
						
						if(acctNo !=null && !acctNo.equalsIgnoreCase("?") && !acctNo.equalsIgnoreCase("")){
							 status = true;
						
						}else{
							badResponseID = WsConstants.BAD_RESPONSE_CODE_0011;
							badResponseDesc = WsConstants.BAD_RESPONSE_DESC_00011;
						}
						  
						
					}else{
						
						badResponseID = WsConstants.BAD_RESPONSE_CODE_0005;
						badResponseDesc = WsConstants.BAD_RESPONSE_DESC_0005;
						
					}
				
			}else{
				
				badResponseID = WsConstants.BAD_RESPONSE_CODE_0004;
				badResponseDesc = WsConstants.BAD_RESPONSE_DESC_0004;
			}
			
		}else{
			badResponseID = WsConstants.BAD_RESPONSE_CODE_0003;
			badResponseDesc = WsConstants.BAD_RESPONSE_DESC_0003;
		}
		
		if(status){
			
			AccountInfo accountInfoObj = new AccountInfo();
			boolean accountExitsStat = accountInfoObj.isAccountExist(acctNo);
			
			if(accountExitsStat){
				
					listOfStatement = object.getListOfStatement(acctNo);
				
			 		if(listOfStatement.size()>0){
			 			
			 			for(int i=0;i<listOfStatement.size();i++){
			 			OMElement el201 = factory.createOMElement("Statement", ns1); 
			 			OMElement el2011 = factory.createOMElement("stmtDate", ns1); 
			 			OMElement el2012 = factory.createOMElement("stmtId", ns1);
			 			String[] details = listOfStatement.get(i).toString().split(",");
			 			
			 			el2011.setText(details[0]);
			 			el2012.setText(details[1]);
			 			el201.addChild(el2011);
			 			el201.addChild(el2012);
			 			el102.addChild(el201);
			 			el100.addChild(el102);
			 			
			 			}
			 		}else{
			 			badResponseID = WsConstants.BAD_RESPONSE_CODE_0002;
						badResponseDesc = WsConstants.BAD_RESPONSE_DESC_0002;
			 			el3011.setText(badResponseID);
						el3012.setText(badResponseDesc);
						el301.addChild(el3011);
						el301.addChild(el3012);
						el100.addChild(el301);
			 		}
				
			}else{
				
				badResponseID = WsConstants.BAD_RESPONSE_CODE_0001;
				badResponseDesc = WsConstants.BAD_RESPONSE_DESC_0001;
				el3011.setText(badResponseID);
				el3012.setText(badResponseDesc);
				el301.addChild(el3011);
				el301.addChild(el3012);
				el100.addChild(el301);
			}
			
		}else{
			
			el3011.setText(badResponseID);
			el3012.setText(badResponseDesc);
			el301.addChild(el3011);
			el301.addChild(el3012);
			el100.addChild(el301);
		}
		
				
	
		
	
		root.addChild(el101);
		root.addChild(el100);
		
						
				
		writer.doLogging(strReqID, "", "GetStatementListResponse", "", root.toString());
		
		
		return root;
}

}

